<html>
<head><meta charset="utf-8"><title>Necessary Parts to Cross-Compile · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html">Necessary Parts to Cross-Compile</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="219724624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219724624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Grommish <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219724624">(Dec 12 2020 at 19:47)</a>:</h4>
<p>I'm incorporating Rust-lang into OpenWrt's Build system (still? again? yes..)  I've gotten to work, mostly, and I've got a ways to go..  This is important to keep in mind that the rust-lang toolchains I'm setting up to build will be varied depending on who is building what OpenWrt target.   Rustup is not an option, and I've already got building from source down.</p>
<p>I generate the distr *.xz files (I discard the .gz), combine them into a single file and then store that compiled toolchain dist to be used in lieu of recompiling.</p>
<p>-rw-r--r-- 1 grommish grommish 460991024 Dec 12 04:37 dl/rust-1.49.0-x86_64-unknown-linux-gnu_mips64-openwrt-linux-musl-install.tar.xz</p>
<p>(I'm defining custom targets)</p>
<p>I'm building with x.py --config ./config.toml dist cargo extended library/std llvm-tools miri rust-dev rustc-dev src src/librustc src/lldb_batchmode.py src/tools/build-manifest to get the complete package..  What, of those, do I need to create the stage 1 host and stage 2 target artifacts that I would use for cross-compiling and what can I put in as "optional end-user parts they can add if they need it"</p>
<p>I know it can be difficult to wrap heads around what I'm trying to do or the environment I'm dealing with (The rust-lang team has always been excellent in helping me in the past!!!), but I can deal with the OpenWrt part of it, I just need guidance on how to best handle rust itself :)</p>



<a name="219724703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219724703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219724703">(Dec 12 2020 at 19:49)</a>:</h4>
<p>to get stage 2 artifacts <code>x.py build --stage 2</code> should work</p>



<a name="219724709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219724709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219724709">(Dec 12 2020 at 19:49)</a>:</h4>
<p>any of the tools are optional, including rustdoc</p>



<a name="219724714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219724714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219724714">(Dec 12 2020 at 19:49)</a>:</h4>
<p>so if you don't want to build rustdoc, you can use <code>build --stage 2 library/std</code></p>



<a name="219724866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219724866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Grommish <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219724866">(Dec 12 2020 at 19:52)</a>:</h4>
<p>I've got the stage 1/2 stuff, I've  got too much of it for defaults..</p>
<div class="codehilite"><pre><span></span><code>./build-manifest-nightly-x86_64-unknown-linux-gnu.tar.xz
./cargo-nightly-x86_64-unknown-linux-gnu.tar.xz
./clippy-nightly-x86_64-unknown-linux-gnu.tar.xz
./llvm-tools-nightly-x86_64-unknown-linux-gnu.tar.xz
./miri-nightly-x86_64-unknown-linux-gnu.tar.xz
./rls-nightly-x86_64-unknown-linux-gnu.tar.xz
./rust-analysis-nightly-x86_64-unknown-linux-gnu.tar.xz
./rust-analyzer-nightly-x86_64-unknown-linux-gnu.tar.xz
./rust-dev-nightly-x86_64-unknown-linux-gnu.tar.xz
./rust-nightly-x86_64-unknown-linux-gnu.tar.xz
./rust-src-nightly.tar.xz
./rust-std-nightly-mips64-openwrt-linux-musl.tar.xz
./rust-std-nightly-x86_64-unknown-linux-gnu.tar.xz
./rustc-dev-nightly-x86_64-unknown-linux-gnu.tar.xz
./rustc-nightly-src.tar.xz
./rustc-nightly-x86_64-unknown-linux-gnu.tar.xz
./rustfmt-nightly-x86_64-unknown-linux-gnu.tar.xz
</code></pre></div>
<p>These are the dist tarballs I create  I want to eventually allow the end-user to choose Any/all, but the compressed tarball is 450mb on-disk/at-rist and I'm not sure everyone NEEDS all those by default</p>



<a name="219724874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219724874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219724874">(Dec 12 2020 at 19:53)</a>:</h4>
<p>oh you're asking which of the <em>distributed</em> files are needed vs optional?</p>



<a name="219724906"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219724906" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Grommish <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219724906">(Dec 12 2020 at 19:53)</a>:</h4>
<p>Correct :)</p>
<p>I've got the hard part out of the way :)</p>



<a name="219724920"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219724920" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219724920">(Dec 12 2020 at 19:53)</a>:</h4>
<p>you could look how rustup does it, <code>--profile minimal</code> is basically what you're asking for it</p>



<a name="219724987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219724987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219724987">(Dec 12 2020 at 19:54)</a>:</h4>
<p>probably just rust-std, rustc, and cargo if you want the absolutely minimum</p>



<a name="219724990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219724990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219724990">(Dec 12 2020 at 19:54)</a>:</h4>
<p>depends how you want to package it</p>



<a name="219725068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219725068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Grommish <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219725068">(Dec 12 2020 at 19:56)</a>:</h4>
<p>rustc/cargo isn't destined to go on the target device, at least not yet and not by default, so everything stays on the build host  I'll look at rust-std/rustc/cargo and see what it breaks :)  Thank you again <span class="user-mention" data-user-id="232545">@Joshua Nelson</span> as you've always been one of those I mentioned who has been fantastic in helping with this (which, to be honest, everyone said I was nuts in the first place).</p>



<a name="219725074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219725074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219725074">(Dec 12 2020 at 19:56)</a>:</h4>
<p>you're very welcome! I hope it works out, I know you've been working on it a while :)</p>



<a name="219725088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219725088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Grommish <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219725088">(Dec 12 2020 at 19:57)</a>:</h4>
<p>Oh, it works.. I just need to tidy up and then begin creating custom triple rs files for the openwrt specific ones. :) One step closer...</p>



<a name="219731617"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219731617" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Grommish <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219731617">(Dec 12 2020 at 22:30)</a>:</h4>
<p>Ok.. Sill question for <span class="user-mention" data-user-id="232545">@Joshua Nelson</span> and <span class="user-mention" data-user-id="116122">@simulacrum</span> .. </p>
<p>If I'm calling <code>x.py dist</code>, do I even NEED the rest?  Or is it going to build out the dist tarballs for everything with just <code>x.py dist</code>?</p>



<a name="219731638"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219731638" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219731638">(Dec 12 2020 at 22:31)</a>:</h4>
<p>as long as you have <code>extended = true</code> it should build everything, I think</p>



<a name="219731639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219731639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219731639">(Dec 12 2020 at 22:31)</a>:</h4>
<p>I haven't actually tried</p>



<a name="219731726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219731726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Grommish <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219731726">(Dec 12 2020 at 22:33)</a>:</h4>
<p>Ok. I'm going to end up having to figure out which is set via configure flags and which I can set via x.py, and what each does so I can detail it..  Joy..  Thank you!  I'll keep testing :)  I think I can set the "build all tools" and "extended" and whatnot via configure and then just call <code>x.py dist</code> maybe.  I'm trying to cut down on the build time for people who don't need everything.</p>



<a name="219731778"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219731778" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219731778">(Dec 12 2020 at 22:34)</a>:</h4>
<p>if we can make <code>./configure</code> simpler let us know, it's very rare to get feedback other than 'you broke the build'</p>



<a name="219731790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219731790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219731790">(Dec 12 2020 at 22:34)</a>:</h4>
<p>in this case I think it should just be <code>--set extended=true</code> on the command lien</p>



<a name="219732043"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219732043" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Grommish <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219732043">(Dec 12 2020 at 22:41)</a>:</h4>
<p><a href="https://github.com/Itus-Shield/packages/blob/rust/lang/rust/Config.in">https://github.com/Itus-Shield/packages/blob/rust/lang/rust/Config.in</a></p>
<p>That is how I currently handle <code>configure</code> inside the <code>make menuconfig</code> environment and below are the static flags.</p>
<div class="codehilite"><pre><span></span><code>CONFIGURE_ARGS = \
  --host=$(RUSTC_HOST_ARCH) \
  --build=$(RUSTC_HOST_ARCH) \
  --target=$(RUSTC_TARGET_ARCH) \
  --prefix=$(CARGO_HOME) \
  --bindir=$(CARGO_HOME)/bin \
  --libdir=$(CARGO_HOME)/lib \
  --sysconfdir=$(CARGO_HOME)/etc \
  --datadir=$(CARGO_HOME)/share \
  --mandir=$(CARGO_HOME)/man \
  --infodir=$(CARGO_HOME)/info \
  --localstatedir=/var \
  --release-channel=nightly \
  --enable-lld \
  --set=target.$(RUSTC_TARGET_ARCH).linker=$(TARGET_CC_NOCACHE) \
  --set=target.$(RUSTC_TARGET_ARCH).cc=$(TARGET_CC_NOCACHE) \
  --set=target.$(RUSTC_TARGET_ARCH).cxx=$(TARGET_CXX_NOCACHE) \
  --set=target.$(RUSTC_TARGET_ARCH).ar=$(TARGET_AR) \
  --set=target.$(RUSTC_TARGET_ARCH).ranlib=$(TARGET_RANLIB)
</code></pre></div>
<p>and I set a conditional MUSL root for musl targets</p>
<div class="codehilite"><pre><span></span><code>ifeq ($(CONFIG_LIBC),&quot;musl&quot;)
CONFIGURE_ARGS += \
     --set=target.$(RUSTC_TARGET_ARCH).musl-root=$(TOOLCHAIN_DIR)
endif
</code></pre></div>
<p>Everything I <em>need</em> is available in <code>configure</code>, although it took me far to long of a time to realize <code>--set</code> was where the real power was :D  Since I can't generate a config.toml ahead of time :)</p>
<p>Suggestions on default settings, etc would be greatly appreciated.  I am NOT a programmer.. I do NOT know Rust..  I know OpenWrt enough to get things to work, but not much beyond that on the dev side.  Rust experts are welcome to chime in and tell me how it should be setup.</p>



<a name="219941623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219941623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Grommish <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219941623">(Dec 15 2020 at 06:22)</a>:</h4>
<p>Update:  I've settles on: <code>x.py --config ./config.toml dist cargo</code> with the following <code>./configure</code> settings:</p>
<p>Static Settings:</p>
<div class="codehilite"><pre><span></span><code>  --host=$(RUSTC_HOST_ARCH) \
  --build=$(RUSTC_HOST_ARCH) \
  --target=$(RUSTC_TARGET_ARCH) \
  --prefix=$(CARGO_HOME) \
  --bindir=$(CARGO_HOME)/bin \
  --libdir=$(CARGO_HOME)/lib \
  --sysconfdir=$(CARGO_HOME)/etc \
  --datadir=$(CARGO_HOME)/share \
  --mandir=$(CARGO_HOME)/man \
  --infodir=$(CARGO_HOME)/info \
  --localstatedir=/var \
  --release-channel=nightly \
  --enable-lld \
  --set=target.$(RUSTC_TARGET_ARCH).linker=$(TARGET_CC_NOCACHE) \
  --set=target.$(RUSTC_TARGET_ARCH).cc=$(TARGET_CC_NOCACHE) \
  --set=target.$(RUSTC_TARGET_ARCH).cxx=$(TARGET_CXX_NOCACHE) \
  --set=target.$(RUSTC_TARGET_ARCH).ar=$(TARGET_AR) \
  --set=target.$(RUSTC_TARGET_ARCH).ranlib=$(TARGET_RANLIB)
</code></pre></div>
<p>Default Optional Settings:</p>
<div class="codehilite"><pre><span></span><code>--enable-option-checking
--enable-ninja
--enable-missing-tools
--enable-manage-submodules
--enable-full-bootstrap
</code></pre></div>
<p>This generates a distro tar-ball that will cross-compile, once installed.</p>
<div class="codehilite"><pre><span></span><code>95888 -rw-r--r-- 1 grommish grommish 98185136 Dec 12 02:44 dl/rust-1.49.0.tar.xz
 3968 -rw-r--r-- 1 grommish grommish  4061580 Dec 14 22:41 dl/rust-1.49.0-x86_64-unknown-linux-gnu_arm-openwrt-linux-muslgnueabi-install.tar.xz
 3968 -rw-r--r-- 1 grommish grommish  4061664 Dec 13 23:40 dl/rust-1.49.0-x86_64-unknown-linux-gnu_mips64-openwrt-linux-musl-install.tar.xz
</code></pre></div>
<p>I'm currently building out various toolchains to see that they build :)  This is an orders of magnitude smaller (literally from 450mb to 4mb) as a default setting.  Things can be changeed by the end-user should they see fit, but I'm working on the "law of defaults" here.  Can anyone see something that should be there and isn't (or the other way around) as a default setting for creating the rustc/cargo compiler package?</p>



<a name="219974886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Necessary%20Parts%20to%20Cross-Compile/near/219974886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Necessary.20Parts.20to.20Cross-Compile.html#219974886">(Dec 15 2020 at 13:03)</a>:</h4>
<p>Looks reasonable to me :) are you sure you want --release-channel=nightly though? That enables unstable features that can break at any time.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>